import numpy as np
import matplotlib.pyplot as plt

import tensorflow as tf

x = tf.Variable(3.0)

# 加入下列语句之后,可以对后面的公式进行逆向求导
with tf.GradientTape() as tape:
    y = x ** 2
    # tape.gradient 对数据进行求导
    dy_dx = tape.gradient(y,x)
    print(dy_dx.numpy())